(function(){
    var oHead = document.getElementsByTagName('head')[0];
    var sBlock = 'header,footer,section,aside,article,nav,hgroup,figure,figcaption,details,summary';
    var sInline = 'time,mark,ruby,rt,rp,output,keygen,meter,progress,command,source';
    var sOther = 'video,audio,canvas,datalist';
    var oStyle = document.createElement('style');
    oStyle.type = 'text/css';
    sCSS = sBlock + '{display:block;margin:0;padding:0;border:none}' + sInline + '{text-decoration:none;font-style:normal;font-weight:normal}';

    if(oStyle.styleSheet){
        var aTags = (sBlock + ',' + sInline + ',' + sOther).split(',');
        for(var i=0;i<aTags.length;i++){
            document.createElement(aTags[i]);
        }
        oStyle.styleSheet.cssText = sCSS;
    }else{
        oStyle.innerHTML = sCSS;
    }
    oHead.appendChild(oStyle);
})();
function $(id){
    return document.getElementById(id);
}
function date(s,t) {
    //s Y-m-d H:i:s
    //t new Date()
    t=t || new Date();
    var re=/Y|m|d|H|i|s/g;
    return s.replace(re,function($1) {
        switch($1) {
            case "Y":return t.getFullYear();
            case "m":return t.getMonth()+1;
            case "d":return t.getDate();
            case "H":return t.getHours();
            case "i":return t.getMinutes();
            case "s":return t.getSeconds();
        }
        return $1;
    });
}
function htmlEncode(html) {
    //return html.replace("<","&lt;").replace(">","&gt;")
    arguments.callee.textNode.nodeValue=html;
    return arguments.callee.div.innerHTML;
}
htmlEncode.div=document.createElement("div");
htmlEncode.textNode=document.createTextNode("");
htmlEncode.div.appendChild(htmlEncode.textNode);
function nextNode(node){
    var temObj=node.nextSibling;
    while(temObj.nodeType!= 1 && temObj.nextSibling!=null){		//1是元素借点
        temObj=temObj.nextSibling;
    }
    return (temObj.nodeType == 1)?temObj:false;
}
function previousNode(node){
    var temObj=node.previousSibling;
    while(temObj.nodeType!=1 && temObj!=null){
        temObj=temObj.previousSibling;
    }
    return (temObj.nodeType ==1) ?temObj :false;
}
function lastSilibing(node){
    var tempObj=node.parentNode.lastChild;
    while(tempObj.nodeType!=1 && tempObj!=null){
        tempObj=tempObj.previousSibling;
    }
    return (tempObj.nodeType==1) ? tempObj : false;
}
function firstSilibing(node){
    var tempObj=node.parentNode.firstChild;
    while(tempObj.nodeType!=1 && tempObj!=null){
        tempObj=tempObj.nextSilibing;
    }
    return (tempObj.nodeType==1) ? tempObj : false;
}
function getText(node){
    if(!node.hasChildNodes()){return false;}
    var reg=/^s+$/;
    while(node.nodeType!=3 && node.nextSilibing!=null || reg.test(node.nodeValue) ){
        node=node.nextSilibing;
    }
    return (node.nodeType==3) ?  node.nodeValue : false;
}
function setText(node,txt){
    if(!node.hasChildNode){
        return false;
    }
    var reg=/^s+$/;
    while(node.nodeType!=3 && node.nextSilibing!=null || reg.test(node.nodeValue)){
        node=node.nextSilibing;
    }
    if(node.nodeType==3) {node.nodeValue = txt} else return false;
}
function createLink(to,txt){
    var tempObj=document.createElement('a');
    tempObj.appendChild(document.createTextNode(txt));
    tempObj.setAttribute('href',to);
    return tempObj;
}
function addEvent(ele,evType,fn,useCapture){
    if(ele.addEventListener){
        ele.addEventListener(evType,fn,useCapture);
    } else
    if(ele.attachEvent){
        ele.attachEvent('on'+evType,fn);
    } else{
        window['on'+evType] = fn;
    }
}
function css(type,node,c1,c2){
    switch (type){
        case 'add':
            if(!css('check',node,c1)){
                node.className+=(node.className?" "+c1:c1);
            }
            break;
        case 'del':
            var rep=node.className.match(' '+c1) ? ' '+c1 : c1;
            node.className=node.className.replace(rep,'');
            break;
        case 'swap':
            node.className=!css('check',node,c1) ? node.className.replace(c2,c1) : node.className.replace(c1,c2);
            break;
        case 'check':
            var found=false;
            var temArray=node.className.split(' ');
            for(var i=0;i<temArray.length;i++){
                if(c1==temArray[i])
                    found=true;
            }
            return found;
            break;
    }
}
function getByClass(className,context) {
    context=context || document;
    if (context.getElementsByClassName) {
        return context.getElementsByClassName(className);
    }
    var nodes=context.getElementsByTagName('*'),
        ret=[];
    for (var i=0;i<nodes.length;i++) {
        if (hasClass(nodes[i],className)) ret.push(nodes[i]);
    }
    return ret;
}
function hasClass(node,className) {
    var names=node.className.split(/\s+/);
    for (var i=0;i<names.length;i++) {
        if (names[i]==className) return true;
    }
    return false;
}

